package com.chenfan.process.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chenfan.process.entity.dto.ProcessTransferDTO;
import com.chenfan.process.entity.po.ProcessTransferLogPo;
import com.chenfan.process.repository.ProcessTransferLogRepository;
import com.chenfan.process.service.ProcessTransferLogService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @author liuming
 * @date 2021/10/26
 */
@Service
public class ProcessTransferLogServiceImpl extends ServiceImpl<ProcessTransferLogRepository, ProcessTransferLogPo>
    implements ProcessTransferLogService {
    @Override
    public Page<ProcessTransferLogPo> pageLog(ProcessTransferDTO processTransfer) {
        Page<ProcessTransferLogPo> page = new Page<>(processTransfer.getPageNum(), processTransfer.getPageSize());
        QueryWrapper<ProcessTransferLogPo> query = new QueryWrapper<>();
        query.like(!StringUtils.isEmpty(processTransfer.getOperatedName()),
            ProcessTransferLogPo.Constants.OPERATED_NAME, processTransfer.getOperatedName());
        query.ge(!StringUtils.isEmpty(processTransfer.getOperatedStartTime()),
            ProcessTransferLogPo.Constants.CREATE_TIME, processTransfer.getOperatedStartTime());
        query.eq(Objects.nonNull(processTransfer.getTransferType()), ProcessTransferLogPo.Constants.TRANSFER_TYPE, processTransfer.getTransferType());
        query.le(!StringUtils.isEmpty(processTransfer.getOperatedEndTime()), ProcessTransferLogPo.Constants.CREATE_TIME,
            processTransfer.getOperatedEndTime());
        query.eq(Objects.nonNull(processTransfer.getStatus()), ProcessTransferLogPo.Constants.STATUS,
            processTransfer.getStatus());
        query.orderByDesc(ProcessTransferLogPo.Constants.CREATE_TIME);
        return this.page(page, query);
    }
}
